package com.dy.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: dy
 * @date: 2024/5/7 10:12
 * @ClassDescription: 同一返回类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResult<T> {
    private String code;
    private Boolean success;
    private String msg;
    private T data;
    public static<T> ApiResult ok(T data){
        return new ApiResult("200",true,null,data);
    }
    public static<T> ApiResult ok(){
        return new ApiResult("200",true,null,null);
    }
    public static<T> ApiResult error(){
        return new ApiResult("-100",false,null,null);
    }
    public static<T> ApiResult error(T data){
        return new ApiResult("-100",false,null,data);
    }

    public static<T> ApiResult error(String msg){
        return new ApiResult("-100",false,msg,null);
    }

    public static<T> ApiResult exceptionError(ErrorEnum errorEnum){
        return new ApiResult("-100",false,errorEnum.getErrorMsg(),null);
    }
}
